package com.lucky.back.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lucky.back.pojo.dto.StoreupAddNewDTO;
import com.lucky.back.pojo.vo.StoreupListItemVO;
import com.lucky.back.service.impl.StoreupServiceImpl;
import com.lucky.back.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 收藏表(Storeup)表控制层
 *
 * @author 张敏锐
 * @since 2022-10-19 20:36:07
 */
@Slf4j
@Api(tags = "09.收藏模块")
@Validated
@RestController
@RequestMapping("storeup")
public class StoreupController {
    @Autowired
    StoreupServiceImpl storeupService;

    @ApiOperation("添加收藏")
    @ApiOperationSupport(order = 102)
    @PostMapping("/add-new")
    public JsonResult addNew(StoreupAddNewDTO storeupAddNewDTO){
        storeupService.addNew(storeupAddNewDTO);
        return JsonResult.ok();
    }



    // http://localhost:9000/albums
    @ApiOperation("查询收藏列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult<List<StoreupListItemVO>> list(){
        List<StoreupListItemVO> list = storeupService.list();
        return JsonResult.ok(list);
    }


    @ApiOperation("删除收藏")
    @ApiOperationSupport(order = 202)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理【删除收藏】的请求，参数：{}", id);
        storeupService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("批量删除收藏")
    @ApiOperationSupport(order = 200)
    @PostMapping("/deleteByIds")
    public JsonResult<Void> deleteByIds(@RequestBody List<Long> list){
        log.debug("开始处理【删除相册】的请求，参数：{}", list);
        storeupService.deleteByIds(list);
        return JsonResult.ok();
    }
}

